package my.data.x.result;

import my.data.x.exception.XException;

public class Result {
    private Object result;
    private String message;
    private String code;
    private Integer tag;

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getTag() {
        return tag;
    }

    public void setTag(Integer tag) {
        this.tag = tag;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public static Result SUCC_RESULT(Object result){
        Result succResult =new Result();
        succResult.setTag(1);
        succResult.setResult(result);
        return succResult;
    }
    public static Result ERR_RESULT(Exception exception){
        Result errResult =new Result();
        errResult.setTag(0);
        if(exception instanceof XException){
            errResult.setCode(((XException) exception).getErrorCodeCode());
        }
        errResult.setMessage(exception.getMessage());
        return errResult;
    }
    public static Result ERR_RESULT(){
        Result errResult =new Result();
        errResult.setTag(0);
        return errResult;
    }
}
